package com.ruchir.prac.services.internal;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ruchir.prac.beans.LicenseBean;

@Repository("hibernateLicenseRepository")
public class HibernateLicenseRepository implements LicenseRepository {

	private SessionFactory sessionFactory;

	@Autowired
	public HibernateLicenseRepository(SessionFactory pSessionFactory) {
		this.sessionFactory = pSessionFactory;
	}

	protected Session getCurrentSession() {
		return sessionFactory.getCurrentSession();
	}

	public LicenseBean findByName(String pLicenseName) {
		return (LicenseBean) getCurrentSession()
				.createQuery(
						"from LicenseBean l where l.licenseName = :LicenseName")
				.setString("LicenseName", pLicenseName).uniqueResult();

	}

}
